home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 41.zip / BS1 part 41 / Devpac 2.12 disk 1.adf / examples / freemem.s < prev    next >
Text File  |  1988-10-06  |  4KB  |  198 lines

  1.  
  2. * file examples/freemem.s
  3.  
  4. * a sample Intuition program to display a window constantly showing
  5. * the free memory figure, until it's closed
  6.  
  7. * this source code (C) HiSoft 1987 All Rights Reserved
  8.  
  9. * both source and binary are FreeWare and may be distributed free of charge
  10. * so long as copyright messages are not removed
  11.  
  12. * revision history:
  13. * 7th June 86    written
  14. * 22nd Sept 86    changed includes
  15.  
  16. * ensure case dependent and debug
  17.     opt    c+,d+
  18.  
  19. * firstly get the required constants and macros
  20.     incdir    ":include/"
  21.  
  22.     include    intuition/intuition.i
  23.     include    intuition/intuition_lib.i
  24.     include    exec/exec_lib.i
  25.     include    graphics/graphics_lib.i
  26.     include    exec/memory.i
  27.     include    libraries/dos_lib.i
  28.     include    libraries/dos.i
  29.  
  30. * constant for frequency of re-display
  31. timeout    equ    25                in 50ths of a second
  32.  
  33. * firstly open the intuition library
  34.     lea    intname(pc),a1
  35.     moveq    #0,d0                dont care which version
  36.     CALLEXEC OpenLibrary
  37.     tst.l    d0
  38.     beq    goawayfast            if didnt open
  39.  
  40.     move.l    d0,_IntuitionBase        store lib pointer
  41.  
  42. * and open the graphics library
  43.     lea    grafname(pc),a1
  44.     moveq    #0,d0
  45.     CALLEXEC OpenLibrary
  46.     tst.l    d0
  47.     beq    goawaycloseint
  48.     move.l    d0,_GfxBase
  49.  
  50. * and open a DOS library
  51.     lea    dosname(pc),a1
  52.     moveq    #0,d0
  53.     CALLEXEC OpenLibrary
  54.     tst.l    d0
  55.     beq    goawayclosegraf
  56.     move.l    d0,_DOSBase
  57.  
  58. * open a window next
  59.     lea    windowdef(pc),a0
  60.     CALLINT    OpenWindow
  61.     tst.l    d0
  62.     beq    goawaycloseall            if no window
  63.     move.l    d0,windowptr            store the pointer
  64.  
  65.     move.l    #-1,oldfreemem
  66.  
  67. * the main loop - display the figure, then wait, then loop
  68. mainloop
  69.     moveq    #MEMF_PUBLIC,d1
  70.     CALLEXEC AvailMem            get the figure
  71.  
  72. * got free mem, see if changed since last time
  73.     cmp.l    oldfreemem,d0
  74.     beq    messagetest            dont print if the same
  75.  
  76.     move.l    d0,oldfreemem
  77.  
  78. * free memory in d0.l, so convert to a hex string
  79. * converting to decimal is left as an exercise to the reader!
  80.  
  81.     lea    thestring(pc),a0
  82.     bsr    hexconvert
  83.  
  84. * replace leading zeros with spaces
  85.     lea    thestring(pc),a0
  86.     moveq    #7-1,d0                max to do
  87. convspaces
  88.     cmp.b    #'0',(a0)
  89.     bne.s    noconvspaces
  90.     move.b    #' ',(a0)+
  91.     dbf    d0,convspaces            convert them
  92. noconvspaces
  93.  
  94. * move the cursor to a suitable place
  95.     moveq    #4,d0                x posn
  96.     moveq    #20,d1                y posn
  97.     move.l    windowptr(pc),a1
  98.     move.l    wd_RPort(a1),a1            get rastport for window
  99.     CALLGRAF Move
  100.  
  101. * and print the string
  102.     move.l    windowptr(pc),a1
  103.     move.l    wd_RPort(a1),a1
  104.     lea    thestring(pc),a0        string
  105.     moveq    #thestringlen,d0        length
  106.     CALLGRAF Text
  107.  
  108. * now see if a message is waiting for me
  109. messagetest
  110.     move.l    windowptr(pc),a0
  111.     move.l    wd_UserPort(a0),a0        windows message port
  112.     CALLEXEC GetMsg
  113.     tst.l    d0
  114.     beq.s    nomessage
  115. * there was a message, which in our case must be CLOSEWINDOW,
  116. * so we should reply then go away
  117.     move.l    d0,a1
  118.     CALLEXEC ReplyMsg
  119.     bra.s    closewindow
  120.  
  121. * no messages waiting, so suspend myself for a short while then
  122. * do it all agaun
  123. nomessage
  124.     move.l    #timeout,d1
  125.     CALLDOS    Delay                wait a while
  126.     bra    mainloop
  127.  
  128. * close clicked so close the window
  129. closewindow
  130.     move.l    windowptr(pc),a0
  131.     CALLINT    CloseWindow
  132.  
  133. * close all the libraries
  134. goawaycloseall
  135.     move.l    _DOSBase,a1
  136.     CALLEXEC CloseLibrary
  137.  
  138. * close the graphics library
  139. goawayclosegraf
  140.     move.l    _GfxBase,a1
  141.     CALLEXEC CloseLibrary
  142.  
  143. * finished so close Intuition library
  144. goawaycloseint
  145.     move.l    _IntuitionBase,a1
  146.     CALLEXEC CloseLibrary
  147.  
  148. goawayfast
  149.     moveq    #0,d0
  150.     rts
  151.  
  152. * convert d0.l into a string at (a0) onwards in hex
  153. hexconvert
  154.     moveq    #8-1,d1            digit count
  155. hexclp    rol.l    #4,d0
  156.     move.l    d0,d2            save it
  157.     and.b    #$f,d0
  158.     cmp.b    #9,d0
  159.     ble.s    hexdig
  160.     addq.b    #7,d0
  161. hexdig    add.b    #'0',d0
  162.     move.b    d0,(a0)+        do a digit
  163.     move.l    d2,d0            restore long
  164.     dbf    d1,hexclp        do all of the digits
  165.     rts
  166.  
  167.  
  168. * window definition here
  169. windowdef    dc.w    50,50            x posn, y posn
  170.     dc.w    200,25                width,height
  171.     dc.b    -1,-1                default pens
  172.     dc.l    CLOSEWINDOW            easy IDCMP flag
  173.     dc.l    WINDOWDEPTH!WINDOWCLOSE!SMART_REFRESH!ACTIVATE!WINDOWDRAG
  174.     dc.l    0                no gadgets
  175.     dc.l    0                no checkmarks
  176.     dc.l    windowtitle            title of window
  177.     dc.l    0                no screen
  178.     dc.l    0                no bitmap
  179.     dc.w    0,0,0,0                minimum, irrelevant as no sizing gadget
  180.     dc.w    WBENCHSCREEN            in workbench
  181.  
  182. * strings here
  183. intname        INTNAME                name of intuition lib
  184. grafname    GRAFNAME            name of graphics library
  185. dosname        DOSNAME                name of dos library
  186.  
  187. windowtitle    dc.b    ' ',$a9,' HiSoft 1987 ',0
  188. thestring    dc.b    '00000000 bytes free'
  189. thestringlen    equ    *-thestring
  190.  
  191. * variables here
  192. _IntuitionBase    dc.l    0            for int library
  193. _GfxBase    dc.l    0            for graphics library
  194. _DOSBase    dc.l    0            for dos library
  195. windowptr    dc.l    0            for window ptr
  196. oldfreemem    dc.l    0            for freemem
  197.  
  198.